package com.wuuxiang.polestar.admin.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.wuuxiang.polestar.admin.dto.IndexDataDto;
import com.wuuxiang.polestar.admin.service.property.IPropertyService;
import com.wuuxiang.polestar.admin.service.team.ITeamService;

/**********************************************************
 * 类名称：IndexController 	<br>
 * 类描述： 首页控制层				<br>
 * 创建人：liuwei 				<br>
 * 创建时间：2017年12月14日下午2:23:21	<br>
 * 修改备注：   					<br>
 **********************************************************/
@RestController
public class IndexController {

	@Autowired
	private IPropertyService propertyService;
	@Autowired
	private ITeamService teamService;
	@RequestMapping("/polestar/indexData")
	@ResponseBody
	public IndexDataDto indexData() {
		IndexDataDto indexDataDto = new IndexDataDto();
		List<String> teamList = teamService.getTeamLst();
		if (teamList != null && teamList.size() > 0) {
			indexDataDto.setTeamCount(teamList.size());
			List<Map<String, Object>> teamDetails = new ArrayList<Map<String, Object>>();
			for (String teamName : teamList) {
				List<String> propertyList = propertyService.getPropertyLst(teamName);
				Map<String, Object> teamDetail = new HashMap<String, Object>();
				teamDetail.put("teamName", teamName);
				if(propertyList == null) {
					teamDetail.put("propertyCount", 0);
				} else {
					teamDetail.put("propertyCount", propertyList.size());
				}
				teamDetails.add(teamDetail);
			}
			indexDataDto.setTeamDetails(teamDetails);
		}
		return indexDataDto;
	}
}
